<?php


namespace app\index\controller;


use think\facade\Cookie;

class TestCookie
{

    public function index()
    {

        Cookie::init([
            'prefix' => "think",
            'expire' => '10',
            'path' => '/'
        ]);
        Cookie::prefix('cui_');
        Cookie::set('user2', '007');
        Cookie::set('user1', '006');
        Cookie::set('user', '007', ['prefix' => "???", 'expire' => '30']);
        dump('是否有名为user的cookie::' . Cookie::has('user1'));
        dump('名为user的cookie值为::' . Cookie::get('user1'));
        Cookie::delete('user1');
        dump('名为user的cookie值为::' . Cookie::get('user1'));
        Cookie::clear('cui_');
    }

    public function supFunction()
    {
        \cookie([
            'prefix' => "function_",
            'expire' => '1000',
            'path' => '/'
        ]);

        \cookie('username', "zhang");
        dump('名为username的cookie值为::' . \cookie('username'));
        \cookie('username', "oh", ['prefix' => "function??", 'expire' => '50']);
        dump('切换前缀后依然获取名为username的cookie值为::' . \cookie('username', '', ['prefix' => "function??_", 'expire' => '50']));
        \cookie('username', null);
        dump('删除名为username的cookie后再次获取username为::' . \cookie('username'));


    }
}